/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var rvm_finder = {
    config: null,
    allDialog: null,
    initialized:false,
    
    init : function( settings ) {
        this.allDialog = new Array();
        
        
        this.initialized=true;
    },
    
    add : function(id, prefix, destField, action,params, showAction, showParams, rf, value){
        this.allDialog[id] ={
          dialogObj :  $j('#' + prefix + id),
          destField :  $j('#' + prefix + destField),
          targetContainer : $j('#result-' + prefix + destField ),
          action : action,
          params : params,
          showAction : showAction,
          showParams : $j.parseJSON(showParams),
          field : rf
        };
        
        
        if(value ){
           this.showSelected(id,value);
        }
    },
    
    open : function(id){
    	//dom_update( this.allDialog[id].action, this.allDialog[id].params, id);
    	$j.ajax( { url: this.allDialog[id].action, cache: false, type: "POST", data: this.allDialog[id].params,
                success: function (data) { 
                	
                                rvm_finder.allDialog[id].dialogObj.html(data);
                                rvm_finder.allDialog[id].dialogObj.dialog({modal: true, width: 'auto', close: this.close, position:"center" });
                } } );
    },
    
    close: function(event){
    	$j(event.target).html("");
    },
    
    select : function(id, data){
        this.allDialog[id].dialogObj.dialog("close");
        
        this.allDialog[id].destField.val(data);
        
        this.showSelected(id, data);
    },
    
    //not used
    showSelected : function(id, data){
        url = this.allDialog[id].showAction
		
		this.allDialog[id].showParams[this.allDialog[id].field] = data;
		
        $j.ajax( { url: url, cache: false, type: "POST", 
        		data: this.allDialog[id].showParams,
                success: function (data) { 
                                rvm_finder.allDialog[id].targetContainer.html(data);
                } } );
    },
    
    setup : function() {
        
    }
}

if(!rvm_finder.initialized){
    rvm_finder.init();
}



